package lc.oa.net;

import android.content.Context;

import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.platform.app.InstrumentationRegistry;

import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.toolbox.JsonObjectRequest;
import com.android.volley.toolbox.RequestFuture;
import com.android.volley.toolbox.Volley;

import org.json.JSONException;
import org.json.JSONObject;
import org.junit.Test;
import org.junit.runner.RunWith;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

/**
 * @Description: java类作用描述
 * @Author: lucifer
 * @CreateDate: 2020/8/10 13:38
 * @UpdateUser:
 * @UpdateDate:
 * @UpdateRemark:
 * @Version: 1.0
 */
@RunWith(AndroidJUnit4.class)
public class LoginTest {
    @Test
    public void testSynchronizationLogin() throws JSONException {
        Context context = InstrumentationRegistry.getInstrumentation().getTargetContext();
        RequestQueue requestQueue = Volley.newRequestQueue(context);
        String url = "http://192.168.1.10:8849/auth-service//api/v1/Login/Login";
        RequestFuture<JSONObject> future = RequestFuture.newFuture();
       // SignData signData = new SignData();
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("loginType", "10");
        jsonObject.put("signData", "");
        jsonObject.put("signVal", "");
        jsonObject.put("userName", "18311329010");
        jsonObject.put("userPassword", "82273a6ba2126d3af24ce2d0cb0af515");
        JsonObjectRequest request = new JsonObjectRequest(Request.Method.POST,url, jsonObject, future, future);
        requestQueue.add(request);

        try {
            JSONObject response = future.get(15000, TimeUnit.MILLISECONDS); // this will block
        } catch (InterruptedException e) {
            // exception handling
            e.printStackTrace();
        } catch (ExecutionException e) {
            // exception handling
            e.printStackTrace();
        } catch (TimeoutException e) {
            e.printStackTrace();
        }
    }
}
